﻿SSVC.Utils.Page.IncludeFile("../styles/UserControl.css", "css");

SSVC.Wrap.Dojo.Require([
    "dojo/_base/fx",
    "dojo/_base/lang",
    "dojo/dom-style",
    "dojo/mouse",
    "dojo/on",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dojo/text!../scripts/UserControl.html"],

	 SSVC.Wrap.Dojo.Hitch(this,
		function(baseFx, lang, domStyle, mouse, on, _WidgetBase, _TemplatedMixin, template)
		{
			return SSVC.Wrap.Dojo.Declare("UserControl", [_WidgetBase, _TemplatedMixin],
			{
				UpdateData: function(userName, telephone, company, email, avatarUrl)
				{
					this.UserNameNode.innerHTML = userName;
					this.CompanyNode.innerHTML = company;
					this.EmailNode.href = "mailto:" + this.email;

					this.EmailNode.innerHTML = email;
					this.TelephoneNode.innerHTML = telephone;
					this.UserAvatarDiv.style.backgroundImage = "url('{0}')".Format(avatarUrl);
				},

				CompanyLabel: SSVC.Utils.GetResource("uc_company"),
				EmailLabel: SSVC.Utils.GetResource("uc_email"),
				TelephoneLabel: SSVC.Utils.GetResource("uc_telephone"),

				templateString: template,

				postCreate: function()
				{
					this.inherited(arguments);

					this.own(
							on(this.UserAvatarNode, "load", lang.hitch(this, "UserAvatarNode_OnLoad")));
				},

				UserAvatarNode_OnLoad: function()
				{
					if (this.UserAvatarNode.naturalWidth > 125)
					{
						this.UserAvatarNode.style.height = "100%";
						this.UserAvatarNode.style.width = "100%";
						if (this.UserAvatarNode.clientHeight > 125)
							this.UserAvatarNode.style.height = "120px";
					}
					else
					{
						this.UserAvatarNode.style.height = this.UserAvatarNode.naturalHeight + "px";
						this.UserAvatarNode.style.width = this.UserAvatarNode.naturalWidth + "px";
					}
				}

			});
		}));

SSVC.Wrap.Dojo.SetObject("SSVC.UI.UserControl", UserControl);